package com.lms.util;

import java.util.ArrayList;
import java.util.List;

public class ResultUtils<T> {
    private Long code;
    private String msg;
    private Long count;
    private List<T> data;

    public ResultUtils() {
    }

    public ResultUtils(Long code, String msg, Long count, List<T> data) {
        this.code = code;
        this.msg = msg;
        this.count = count;
        this.data = data;
    }

    public static <T> ResultUtils<T> layUITable(Long totalCount, List<T> pageData) {
        return new ResultUtils<T>(0L, "OK", totalCount, pageData);
    }

    public static <T> ResultUtils<T> success(T object) {
        List<T> data = new ArrayList<>();
        data.add(object);
        return new ResultUtils<T>(200L, "success", 1L, data);
    }

    public static <T> ResultUtils<T> failed(String msg) {
        return new ResultUtils<T>(500L, msg, 0L, new ArrayList<T>());
    }

    public static <T> ResultUtils<T> failed() {
        return ResultUtils.failed("failed!");
    }

    public Long getCode() {
        return code;
    }

    public void setCode(Long code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Long getCount() {
        return count;
    }

    public void setCount(Long count) {
        this.count = count;
    }

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "ResultUtils{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", count=" + count +
                ", data=" + data +
                '}';
    }
}
